package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import com.ruoyi.system.domain.Demo;
import org.springframework.security.access.prepost.PreAuthorize;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IDemoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 演示
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/demo")
public class DemoController extends BaseController {

    private final IDemoService iDemoService;

    /**
     * 查询演示列表
     */
    @PreAuthorize("@ss.hasPermi('system:demo:list')")
    @GetMapping("/list")
    public TableDataInfo<Demo> list(Demo bo, PageQuery pageQuery) {
        return iDemoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出演示列表
     */
    @PreAuthorize("@ss.hasPermi('system:demo:export')")
    @Log(title = "演示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Demo bo, HttpServletResponse response) {
        List<Demo> list = iDemoService.queryList(bo);
        ExcelUtil<Demo> util = new ExcelUtil<Demo>(Demo.class);
        util.exportExcel(response,list, "演示");
    }

    /**
     * 获取演示详细信息
     *
     * @param id 主键
     */
    @PreAuthorize("@ss.hasPermi('system:demo:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return success(iDemoService.queryById(id));
    }

    /**
     * 新增演示
     */
    @PreAuthorize("@ss.hasPermi('system:demo:add')")
    @Log(title = "演示", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult add(@Validated @RequestBody Demo bo) {
        return toAjax(iDemoService.insert(bo));
    }

    /**
     * 修改演示
     */
    @PreAuthorize("@ss.hasPermi('system:demo:edit')")
    @Log(title = "演示", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult edit(@Validated @RequestBody Demo bo) {
        return toAjax(iDemoService.update(bo));
    }

    /**
     * 删除演示
     *
     * @param ids 主键串
     */
    @PreAuthorize("@ss.hasPermi('system:demo:remove')")
    @Log(title = "演示", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iDemoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
